package com.huha.tools.utils;

import java.util.Stack;

public class CreateVOCode {

    // 生成每个key对应的get、set方法
    public static String createvobykey(String key) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("public String get").append(key.substring(0, 1).toUpperCase()).append(key.substring(1)).append(
                "() { return this.getStr(\"" + key + "\");}");
        stringBuilder.append("public void set").append(key.substring(0, 1).toUpperCase()).append(key.substring(1)).append("(String ").append(key).append(") { this.set(\"").append(key)
                .append("\", ").append(key).append(");}");
        return stringBuilder.toString();
    }

    // 生成固定的VO代码
    public static  String createvo(String inputText){
        StringBuilder stringBuilder = new StringBuilder();
        String[] lines = inputText.split("\n");
        stringBuilder.append("public static final String[] KEYS = new String[] {");
        for (String line : lines) {
            stringBuilder.append("\"").append(line).append("\",\n");
        }
        stringBuilder.deleteCharAt(stringBuilder.length() - 2);
        stringBuilder.append("};");
        stringBuilder.append("public String[] getKeys() {\n" +
                "        return KEYS;\n" +
                "    }");
        return stringBuilder.toString();
    }

    public static void createvobykeys(String[] KEYS) {
        for (String key : KEYS) {
            System.out.println("public String get" + key.substring(0, 1).toUpperCase() + key.substring(1)
                    + "() { return this.getStr(\"" + key + "\");}");
            System.out.println("public void set" + key.substring(0, 1).toUpperCase() + key.substring(1) + "(String "
                    + key + ") { this.set(\"" + key + "\", " + key + ");}");
        }
    }
}
